package com.engc.stumng.web.army;

import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.engc.common.service.BaseService;
import com.engc.common.utils.BaseUtils;

/**
 * 军训事务管理
 * 
 * @author gxx
 * 
 */
@Controller
@RequestMapping("/armyGoods")
public class ArmyGoodsController {

	@Resource
	private BaseService baseService;

	@RequestMapping("/view")
	public String view(HttpServletRequest request) {
		return "army/armygoods";
	}

	@RequestMapping("/getNames")
	@ResponseBody
	public List<Map<String, Object>> getUser(HttpServletRequest request)
	{
		String sql = "select id,name text from t_auth_info where auth_status=1 and id not in (select auth_id from t_army_goods)";
		
		List<Map<String, Object>> list = baseService.Query(sql);
		
		return list;
	}
	
	/**
	 * 新增
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping("/insert")
	@ResponseBody
	public Map<String, Object> insert(HttpServletRequest request) {
		Map<String, Object> record = BaseUtils.getInsertParam(request);
		try {
			record.put("id", System.currentTimeMillis());
			baseService.Insert("t_army_goods", record);
			return BaseUtils.getSuccessMessage("登记成功");
		} catch (Exception e) {
			return BaseUtils.getErrorMessage("登记失败");
		}
	}

	/**
	 * 修改
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping("/update")
	@ResponseBody
	public Map<String, Object> update(HttpServletRequest request) {
		Map<String, Object> record = BaseUtils.getUpdateParam(request);

		try {
			baseService
					.Update("t_army_goods", record, "id=?", record.get("id"));
			return BaseUtils.getSuccessMessage("修改成功");
		} catch (Exception e) {
			return BaseUtils.getErrorMessage("修改失败");
		}
	}
}
